package com.medical.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.medical.system.common.Result;
import com.medical.system.mapper.SchedulingMapper;
import com.medical.system.model.Scheduling;
import com.medical.system.service.DoctorService;
import com.medical.system.service.SchedulingService;
import com.medical.system.vo.SchedulingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SchedulingServiceImpl extends ServiceImpl<SchedulingMapper, Scheduling> implements SchedulingService {

    @Autowired
    DoctorService doctorService;

    @Override
    public Result selectPage(Long page,Long limit, SchedulingVo schedulingVo) {
//        创建Scheduling分页
        IPage<Scheduling> iPage = new Page<>(page, limit);
        IPage<Scheduling> schedulingIPage = this.baseMapper.selectPage(iPage, schedulingVo);
        return Result.ok(schedulingIPage);
    }


    @Override
    public Result findAll() {
        List<Scheduling> list = baseMapper.selectList(null);
        if (list != null) {

            return Result.ok(list);
        }
        return Result.fail();
    }

    @Override
    public Result findById(Long id) {
        Scheduling scheduling = baseMapper.selectById(id);
        if (scheduling != null) {
            return Result.ok(scheduling);
        }
        return Result.fail();
    }

    @Override
    public Result addScheduling(Scheduling scheduling) {
        int i = baseMapper.insert(scheduling);
        if (i > 0) {
            return Result.ok();
        }
        return Result.fail();
    }

    @Override
    public Result updateScheduling(Scheduling scheduling) {
        int i = baseMapper.updateById(scheduling);
        if (i > 0) {
            return Result.ok();
        }
        return Result.fail();
    }

    @Override
    public Result deleteScheduling(Long id) {
        int i = baseMapper.deleteById(id);
        if (i > 0) {
            return Result.ok();
        }
        return Result.fail();
    }



}
